package com.project.genesis.admin.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.project.genesis.common.constant.RabbitMQEnum.*;

/**
 * @author xnd
 * @since 2023/8/3 9:28
 */
@Configuration
public class MsgCenterQueueConfig {

    @Bean
    public DirectExchange MsgCenterExchange() {
        //使用建造者模式创建
        return ExchangeBuilder.directExchange(MESSAGE_CENTER_EXCHANGE).build();
    }

    @Bean
    public Queue msgCenterQueue() {
        //建造者模式创建
        return QueueBuilder.durable(MESSAGE_CENTER_QUEUE).build();
    }

    @Bean
    public Binding msgCenterBinding() {
        return BindingBuilder.bind(msgCenterQueue()).to(MsgCenterExchange()).with(MESSAGE_CENTER_ROUTING_KEY);
    }
}
